import QtQuick 2.6
import QtQuick.Layouts 1.1
import Qt.labs.controls 1.0
import QtQuick.XmlListModel 2.0
import "../template" as Tm
import "../js/PlaceNavigator.qml.js" as Jit
Tm.Navigator {
    id: nav
    title: "场地管理"

    XmlListModel {
        id: xmlModel
        source: http.build("/place.xml?t=s", {uid: usinfo.id})
        query: "/places/place"

        XmlRole { name: "id"; query: "id/string()" }
        XmlRole { name: "name"; query: "name/string()" }
    }


    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 9
        ListView {
            id: listView

            model:xmlModel
            Layout.fillHeight: true
            Layout.fillWidth: true


            delegate: ItemDelegate{
                width: listView.width

                text: "场地名称：" + name


                Rectangle {
                    anchors.bottom: parent.bottom
                    color: "gainsboro"
                    width: parent.width
                    height: 1
                    visible: index != listView.count - 1
                }

                onClicked: {input.text = name;
                    mwindow.itemid = id; listView.currentIndex = index;  mwindow.open()}
            }
        }

        Button {
            text: "增加场地"
            anchors.horizontalCenter: parent.horizontalCenter
             onClicked: {input.editable = false; input.text = ""; input.open()}
            Layout.preferredWidth: implicitWidth * 2
        }
        Tm.MenuWindow {
            id: mwindow
            onEditTriggered: Jit.edit()
            onDelTriggered: Jit.del()
        }

        Tm.InputView{id: input
            title: "场地"
            property bool editable: false
            onClicked: editable ? Jit.editcommit() : Jit.addcommit()
            label: "名称"
        }

    }
}
